// 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));

var labelfontcolor = "#f3f878" //省份标签字体颜色
var labellightfontcolor = "#d05848" //省份标签字体选中时颜色
var itemareacolor = "#6d58f030" //省份颜色
var itemareacolorlight = "#4155b9a0" //省份选中时颜色
var itembordercolor = "#389dff" //省份边界颜色
var itemshadowcolor = "#556e75" //省份阴影颜色
var pointcolor = "#68bd0a" //点颜色
var bgcolor = "#0d005900" //背景颜色

// 指定图表的配置项和数据
var name_title = "莱阳一中 67 级 2 班蹭饭地图"
var mapName = 'china'
var data = [
    { name: "刘恒源", school: "浙江大学", telecom: "18561092068", city: "Zhe Jiang"},
    { name: "刘炫", school: "青岛大学", telecom: "13573520278", city: "Shan Dong"},
    { name: "赵文磊", school: "国防科技大学", telecom: "15266555755", city: "Hu Nan"},
    { name: "门晓露", school: "北京中医药大学", telecom: "15194362002", city: "Bei Jing"},
    { name: "李皓博", school: "山东大学", telecom: "18005456389", city: "Shan Dong"},
    { name: "李广行", school: "上海大学", telecom: "15165789883", city: "Shang Hai"},
    { name: "任富华", school: "厦门大学", telecom: "17196707891", city: "Fu Jian"},
    { name: "吕绍勋", school: "哈尔滨工业大学", telecom: "0", city: "Hei Long Jiang"},
    { name: "程奕欣", school: "中国药科大学", telecom: "18854579705", city: "Jiang Su"},
    { name: "尹新琰", school: "中山大学", telecom: "18766691095", city: "Guang Dong"},
    { name: "栾浩文", school: "中国海洋大学", telecom: "0", city: "Shan Dong"},
    { name: "李谦益", school: "中国石油大学", telecom: "13356383727", city: "Shan Dong"},
    { name: "刘忠艳", school: "中国石油大学", telecom: "13792511719", city: "Shan Dong"},
    { name: "初小宇", school: "大连理工大学", telecom: "17686025662", city: "Liao Ning"},
    { name: "梁子芮", school: "华南理工大学", telecom: "15064560737", city: "Guang Dong"},
    { name: "王尔昊", school: "南开大学", telecom: "13708912980", city: "Tian Jin"},
    { name: "于稑翔", school: "天津大学", telecom: "15966485205", city: "Tian Jin"},
    { name: "宋恩宇", school: "吉林大学", telecom: "17125304575", city: "Ji Lin"},
    { name: "刘亚通", school: "吉林大学", telecom: "15266577702", city: "Ji Lin"},
    { name: "赵官芸", school: "湖南大学", telecom: "17616017758", city: "Hu Nan"},
    { name: "荆熙", school: "海军工程大学", telecom: "15965135309", city: "Hu Bei"},
    { name: "赵克蒙", school: "山东中医药大学", telecom: "17653536901", city: "Shan Dong"},
    { name: "蓝航", school: "东北大学", telecom: "15605453230", city: "Liao Ning"},
    { name: "初锦杰", school: "暨南大学", telecom: "0", city: "Guang Dong"},
    { name: "宋思威", school: "哈尔滨工业大学 (威海)", telecom: "17660822529", city: "Shan Dong"},
    { name: "迟淇文", school: "暨南大学", telecom: "13562594138", city: "Guang Dong"},
    { name: "宋永昆", school: "吉林大学", telecom: "13589792585", city: "Ji Lin"},
    { name: "盖冰冰", school: "合肥工业大学", telecom: "15966485863", city: "An Hui"},
    { name: "尉家林", school: "中国海洋大学", telecom: "13256950492", city: "Shan Dong"},
    { name: "吕嘉琦", school: "北京林业大学", telecom: "17853516056", city: "Bei Jing"},
    { name: "于斐", school: "山东大学", telecom: "15553590628", city: "Shan Dong"},
    { name: "宋鹏辉", school: "山东科技大学", telecom: "13031632925", city: "Shan Dong"},
    { name: "高启俊", school: "上海交通大学", telecom: "13181603631", city: "Shang Hai"},
    { name: "吕峻峰", school: "山东大学", telecom: "15587386171", city: "Shan Dong"},
    { name: "初辰星", school: "西安电子科技大学", telecom: "18562247608", city: "Shann Xi"},
    { name: "刘明骆", school: "中山大学", telecom: "17616192317", city: "Guang Dong"},
    { name: "梁雅婷", school: "山东大学", telecom: "18769445960", city: "Shan Dong"},
    { name: "王新杰", school: "莱阳一中", telecom: "13256969125", city: "Shan Dong"},
    { name: "周蕴", school: "青岛大学", telecom: "13708916197", city: "Shan Dong"},
    { name: "祝溱", school: "青岛科技大学", telecom: "13081632967", city: "Shan Dong"},
    { name: "闫佳伟", school: "南京工业大学", telecom: "15063884072", city: "Jiang Su"},
    { name: "田绍杰", school: "武汉理工大学", telecom: "13723953108", city: "Hu Bei"},
    { name: "宋吉哲", school: "青岛大学", telecom: "15552222833", city: "Shan Dong"},
    { name: "迟淇文", school: "暨南大学", telecom: "13562594138", city: "Guang Dong"},
    { name: "贾惠清", school: "山东第一医科大学", telecom: "15306380186", city: "Shan Dong"},
    { name: "刘昭辰", school: "湖南中医药大学", telecom: "0", city: "Hu Nan"},
    { name: "刘中祥", school: "天津中医药大学", telecom: "0", city: "Tian Jin"}
];

function getHTML(x) {
    var flag = 0;
    console.log(x);
    if (typeof(x) != "string")
        return null;
    var res = "";
    for (var i in data) {
        if (data[i].city == x) {
            if (!flag)
                flag = 1;
            else
                res += "<br>";
            res += "<sup>" + data[i].name + "  |  " + data[i].school + "  |  电话: " + ((data[i].telecom == "0") ? "暂无" : data[i].telecom) + "</sup>";
        }
    }
    return res === "" ? "暂无" : res;
}

var option = {
    backgroundColor: bgcolor,
    title: {
        text: name_title,
        x: 'center',
        y: 20,
        shadowColor: "rgba(0, 0, 0, 0.5)",
        textStyle: {
            fontSize: 24,
            color: "#ffffff",
        },
    },
    tooltip: {
        trigger: 'item',
        textStyle: {
            fontSize: 15
        },
        formatter: function (params) {
            var toolTiphtml = ''
            /*params.seriesName params.name params.value[0]*/
            if (params.value[0] === 253) {
                toolTiphtml = getHTML("Xin Jiang");
            } // Xin Jiang
            if (params.value[0] === 266) {
                toolTiphtml = getHTML("Xi Zang");
            } // Xi Zang
            if (params.value[0] === 394) {
                toolTiphtml = getHTML("Gan Su");
            } // Gan Su
            if (params.value[0] === 347) {
                toolTiphtml = getHTML("Qing Hai");
            } // Qing Hai
            if (params.value[0] === 468) {
                toolTiphtml = getHTML("Si Chuan");
            } // Si Chuan
            if (params.value[0] === 446) {
                toolTiphtml = getHTML("Yun Nan");
            } // Yun Nan
            if (params.value[0] === 515) {
                toolTiphtml = getHTML("Nei Meng Gu");
            } // Nei Meng Gu
            if (params.value[0] === 513) {
                toolTiphtml = getHTML("Ning Xia");
            } // Ning Xia
            if (params.value[0] === 548) {
                toolTiphtml = getHTML("Chong Qing");
            } // Chong Qing
            if (params.value[0] === 531) {
                toolTiphtml = getHTML("Gui Zhou");
            } // Gui Zhou
            if (params.value[0] === 561) {
                toolTiphtml = getHTML("Guang Xi");
            } // Guang Xi
            if (params.value[0] === 629) {
                toolTiphtml = getHTML("Guang Dong");
            } // Guang Dong
            if (params.value[0] === 559) {
                toolTiphtml = getHTML("Hai Nan");
            } // Hai Nan
            if (params.value[0] === 547) {
                toolTiphtml = getHTML("Shann Xi");
            } // Shann Xi
            if (params.value[0] === 569) {
                toolTiphtml = getHTML("Hu Bei");
            } // Hu Bei
            if (params.value[0] === 578) {
                toolTiphtml = getHTML("Hu Nan");
            } // Hu Nan
            if (params.value[0] === 591) {
                toolTiphtml = getHTML("Shan Xi");
            } // Shan Xi
            if (params.value[0] === 607) {
                toolTiphtml = getHTML("He Nan");
            } // He Nan
            if (params.value[0] === 638) {
                toolTiphtml = getHTML("Jiang Xi");
            } // Jiang Xi
            if (params.value[0] === 659) {
                toolTiphtml = getHTML("Fu Jian");
            } // Fu Jian
            if (params.value[0] === 691) {
                toolTiphtml = getHTML("Tai Wan");
            } // Tai Wan
            if (params.value[0] === 630) {
                toolTiphtml = getHTML("He Bei");
            } // He Bei
            if (params.value[0] === 639) {
                toolTiphtml = getHTML("Bei Jing");
            } // Bei Jing
            if (params.value[0] === 651) {
                toolTiphtml = getHTML("Tian Jin");
            } // Tian Jin
            if (params.value[0] === 638) {
                toolTiphtml = "由于山东人口太多，请移步至左下角圆点查看";
            } // Shan Dong
            if (params.value[0] == 0) {
                toolTiphtml = getHTML("Shan Dong");
            } // Shan Dong New
            if (params.value[0] === 645) {
                toolTiphtml = getHTML("An Hui");
            } // An Hui
            if (params.value[0] === 687) {
                toolTiphtml = getHTML("Zhe Jiang");
            } // Zhe Jiang
            if (params.value[0] === 703) {
                toolTiphtml = getHTML("Shang Hai");
            } // Shang Hai
            if (params.value[0] === 668) {
                toolTiphtml = getHTML("Jiang Su");
            } // Jiang Su
            if (params.value[0] === 780) {
                toolTiphtml = getHTML("Hei Long Jiang");
            } // Hei Long Jiang
            if (params.value[0] === 728) {
                toolTiphtml = getHTML("Ji Lin");
            } // Ji Lin
            if (params.value[0] === 732) {
                toolTiphtml = getHTML("Liao Ning");
            } // Liao Ning
            // console.log(toolTiphtml)
            return toolTiphtml;
        }
        // axisPointer: {
        //     show: false, //开发时用于取某个坐标点用
        //     type: 'cross',
        //     lineStyle: {
        //         type: 'dashed',
        //         width: 1
        //     }
        // }
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    geo: {
        show: true,
        map: mapName,
        label: {
            normal: {
                show: true,
                fontSize: 10,
                color: labelfontcolor
            },
            emphasis: {
                show: false,
                color: labellightfontcolor,
                fontSize: 20
            }
        },
        roam: false, //不允许缩放，散点图太娇气了
        zoom: 1.6,
        center: [105, 36], // 调整地图位置
        itemStyle: {
            normal: {
                areaColor: itemareacolor,
                borderColor: itembordercolor,
                borderWidth: 1, //设置外层边框
                shadowBlur: 5,
                shadowOffsetY: 8,
                shadowOffsetX: 0,
                shadowColor: itemshadowcolor
            },
            emphasis: {
                areaColor: itemareacolorlight,
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowBlur: 5,
                borderWidth: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
            }
        }
    },
    xAxis: {
        show: false,
        min: 0,
        max: 1000
    },
    yAxis: {
        show: false,
        min: 0,
        max: 1000
    },
    series: [
        {
            type: 'map',
            map: mapName,
            geoIndex: 0,
            coordinateSystem: 'geo', // 坐标系为地理坐标系
            animation: true,
            data: data
        },
        {
            symbolSize: 20,
            symbol: 'circle',
            data: [
                //[0,0], //左下角点                    
                [253, 567], // Xin Jiang
                [266, 364], // Xi Zang
                [394, 629], // Gan Su
                [347, 512], // Qing Hai
                [468, 388], // Si Chuan
                [446, 117], // Yun Nan
                [515, 660], // Nei Meng Gu
                [513, 578], // Ning Xia
                [548, 360], // Chong Qing
                [531, 260], // Gui Zhou
                [561, 162], // Guang Xi
                [629, 131], // Guang Dong
                [559, 3], // Hai Nan
                [547, 445], // Shan Xi
                [569, 391], // Hu Bei
                [578, 284], // Hu Nan
                [591, 598], // Shan Xi
                [607, 479], // He Nan
                [638, 278], // Jiang Xi
                [659, 237], // Fu Jian
                [691, 123], // Tai Wan
                [630, 580], // He Bei
                [639, 635], // Bei Jing
                [651, 596], // Tian Jin
                [638, 479], // Shan Dong
                [645, 419], // An Hui
                [687, 330], // Zhe Jiang
                [703, 359], // Shang Hai
                [668, 448], // Jiang Su
                [780, 837], // Hei Long Jiang
                [728, 773], // Ji Lin
                [732, 684] // Liao Ning
                //[1000,1000] //右上角点
            ],
            type: 'scatter',
            itemStyle: {
                color: pointcolor
            }
        },
        {
            symbolSize: 20,
            symbol: 'circle',
            data: [
                [0, 0], //左下角点                    
            ],
            type: 'scatter',
            itemStyle: {
                color: pointcolor
            }
        }
    ]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);